"""
urllib3类库的helloWorld
"""
import ssl

from urllib3 import PoolManager

base_url = 'http://www.bing.com'

user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'

"""
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='cn.bing.com', port=443): Max retries exceeded with url: /?toHttps=1&redig=7FC431BF12E34D87A7AB824F59D0C04C (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')))
解决方案: cert_reqs=ssl.CERT_NONE: Ignoring SSL verification

PoolManager: 连接池管理器
"""
with PoolManager(cert_reqs=ssl.CERT_NONE) as poolManager:
    response = poolManager.request('GET', base_url, headers={'User-agent': user_agent})
    # urllib3.response.HTTPResponse
    print(type(response))
    """
    类似java的cast强转，方便实用转换以后对象中的方法，仅供方便开发使用
    response: HTTPResponse = HTTPResponse()
    """
    print(response.status, response.reason)
    print(response.headers)
    print(response.data)
